package com.dq.controller.api.merchant.workbench.customer;

import com.dq.exception.customException.AdminException;
import com.dq.controller.in.CusArrearsQuery;
import com.dq.vo.Vo;
import com.dq.domain.record.ArrearsRecord;
import com.dq.service.AllService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;

/**
 * @author liuhui
 * @date 2019/11/25 0025 10:33:05
 */
@RestController
@RequestMapping("/api/merchant/workbench/customer/arrears")
@Api(description = "欠款记录")
public class CusArrearsController extends AllService {

    @PostMapping("/list")
    @ApiOperation("多条件检索顾客欠款记录")
    public Vo list(@RequestBody CusArrearsQuery cusArrearsQuery)throws AdminException {
        List<ArrearsRecord> arrearsRecordList = cusArrearsService.findByWhere(cusArrearsQuery);
        Long totalCount = cusArrearsService.countByWhere(cusArrearsQuery);
        List<ArrearsRecord.OrgListVo> orgListVos = new ArrayList<>();
        arrearsRecordList.forEach(arrearsRecord -> {orgListVos.add(arrearsRecord.toOrgListVo());});
        PageInfo pageInfo = new PageInfo(orgListVos);
        pageInfo.setTotal(totalCount);
        return new Vo(pageInfo);
    }
}
